﻿//两整数之和（medium):https://leetcode.cn/problems/sum-of-two-integers/description/
class Solution {
public:
    int getSum(int a, int b) {
        //a+b=a^b+进位（a&b<<1)
        int m = a ^ b;
        int bit = (a & b) << 1;
        while (bit)
        {
            int m1 = m ^ bit;
            int bit1 = (m & bit) << 1;
            m = m1;
            bit = bit1;
        }
        return m;
    }
};

//只出现⼀次的数字 II（medium）:https://leetcode.cn/problems/single-number-ii/submissions/572197545/
class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int m = 0;
        for (int i = 0; i < 32; i++)
        {
            int ret = 0;
            for (auto x : nums)
            {
                ret += (x >> i) & 1;
            }
            ret %= 3;
            //m+=(ret<<i);
            if (ret == 1)    m |= (1 << i);
        }
        return m;
    }
};